
#include<vector>

#include <unistd.h>
#include <errno.h>
#include <sys/iomsg.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "../m_connection_tests/komunikacja1.2.h"

using namespace std;

Message::Message()
{
	data.type = -1; 

	for( int i = 0; i < CONN_NAME_LENGTH; i++) {
		data.connSenderName[i] = NULL;
		data.connReceiverName[i] = NULL;
		data.argStr1[i] = NULL;
		data.argStr2[i] = NULL;
	}
		
		
	data.msgLength = -1;
	data.nr = -1;
	
	
	data.argInt1 = -1;
	data.argInt2 = -1;
	data.argInt3 = -1;
	data.argInt4 = -1;
	
	data.argBool1 = true;

	data.argFloat1 = -1;
	data.argFloat2 = -1;	
	data.argFloat3 = -1;	
	

}

	
/**
			gety i sety
**/



void Message::setType( int _type)
{
     data.type = _type;
}

int Message::getType( void)
{
     return data.type;
}

char * Message::getConnSenderName(void)
{
	return data.connSenderName;
}

void Message::setConnSenderName(char* arg)
{
	for(int i = 0 ; i < CONN_NAME_LENGTH; i++)
	{
		if( *(arg+i) != NULL)
			data.connSenderName[i] = *(arg+i);
		else
			data.connSenderName[i] = NULL;
	}
	//cout << "setConnName. Nowa nazwa : " << data.connName <<endl;
	return;
}

char * Message::getConnReceiverName(void)
{
	return data.connReceiverName;
}

void Message::setConnReceiverName(char* arg)
{
	//cout << "otrzymalem :" << arg <<endl;
	for(int i = 0 ; i < CONN_NAME_LENGTH; i++)
	{
		if( *(arg+i) != NULL)
			data.connReceiverName[i] = *(arg+i);
		else
			data.connReceiverName[i] = NULL;
	}
	//cout << "setConnName. Nowa nazwa : " << data.connReceiverName <<endl;
	return;
}


void Message::setMessageLength( int arg)
{
	data.msgLength = arg;
}

int Message::getMessageLength(void)
{
	return data.msgLength;
}
   
void Message::setNr( int arg)
{
	data.nr = arg;
}

int Message::getNr(void)
{
	return data.nr;
}


int Message::getIntArg1(void)
{
	return data.argInt1;
}

void Message::setIntArg1(int arg)
{
	data.argInt1 = arg;
}

int Message::getIntArg2(void)
{
	return data.argInt2;
}

void Message::setIntArg2(int arg)
{
	data.argInt2 = arg;
}

int Message::getIntArg3(void)
{
	return data.argInt3;
}

void Message::setIntArg3(int arg)
{
	data.argInt3 = arg;
}

int Message::getIntArg4(void)
{
	return data.argInt4;
}

void Message::setIntArg4(int arg)
{
	data.argInt4 = arg;
}

bool Message::getBoolArg1(void)
{
	return data.argBool1;
}

void Message::setBoolArg1(bool arg)
{
	data.argBool1 = arg;
}
	
	
float Message::getFloatArg1(void)
{
	return data.argFloat1;
}

void Message::setFloatArg1( float arg)
{
	data.argFloat1 = arg;
}

float Message::getFloatArg2(void)
{
	return data.argFloat2;
}

void Message::setFloatArg2( float arg)
{
	data.argFloat2 = arg;
}

float Message::getFloatArg3(void)
{
	return data.argFloat3;
}

void Message::setFloatArg3( float arg)
{
	data.argFloat3 = arg;
}


char * Message::getStringArg1(void)
{
	return data.argStr1;
}

void Message::setStringArg1( char * arg)
{
	
	for(int i = 0 ; i < CONN_NAME_LENGTH; i++)
	{
		if( *(arg+i) != NULL)
			data.argStr1[i] = *(arg+i);
		else
			data.argStr1[i] = NULL;
	}

	return;
}



char * Message::getStringArg2(void)
{
	return data.argStr2;
}

void Message::setStringArg2( char * arg)
{
	
	for(int i = 0 ; i < CONN_NAME_LENGTH; i++)
	{
		if( *(arg+i) != NULL)
			data.argStr2[i] = *(arg+i);
		else
			data.argStr2[i] = NULL;
	}

	return;
}



void Message::copyMessage( Message * ptr)
{
	ptr->data.type = data.type;

	strncpy( ptr->data.connSenderName,  data.connSenderName,  CONN_NAME_LENGTH);
	strncpy( ptr->data.connReceiverName, data.connReceiverName,  CONN_NAME_LENGTH);
	strncpy( ptr->data.argStr1, data.argStr1,   CONN_NAME_LENGTH);
	strncpy( ptr->data.argStr2, data.argStr2,   CONN_NAME_LENGTH);
	ptr->data.nr = data.nr;						// nr elementu w wektorze	
	ptr->data.msgLength = data.msgLength;			// dlugosc przesylanego wektora
	
	ptr->data.argInt1 = data.argInt1;
	ptr->data.argInt2 = data.argInt2;
	ptr->data.argInt3 = data.argInt3;
	ptr->data.argInt4 = data.argInt4;
	
	ptr->data.argBool1 = data.argBool1;
	
	ptr->data.argFloat1 = data.argFloat1;
	ptr->data.argFloat2 = data.argFloat2;
	ptr->data.argFloat3 = data.argFloat3;
	
}




